<!DOCTYPE HTML PUBLIC "-//ORA//DTD CD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>[Chapter 18] Checksum</TITLE>
<META NAME="author" CONTENT="Mark Grand and Jonathan Knudsen">
<META NAME="date" CONTENT="Fri Aug  8 17:48:55 1997">
<META NAME="form" CONTENT="html">
<META NAME="metadata" CONTENT="dublincore.0.1">
<META NAME="objecttype" CONTENT="book part">
<META NAME="otheragent" CONTENT="gmat dbtohtml">
<META NAME="publisher" CONTENT="O'Reilly &amp; Associates, Inc.">
<META NAME="source" CONTENT="SGML">
<META NAME="subject" CONTENT="Java">
<META NAME="title" CONTENT="Java Fundamental Classes Reference">
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
</HEAD>
<body vlink="#551a8b" alink="#ff0000" text="#000000" bgcolor="#FFFFFF" link="#0000ee">

<DIV CLASS=htmlnav>
<H1><a href='index.htm'><IMG SRC="gifs/smbanner.gif"
     ALT="Java Fundamental Classes Reference" border=0></a></H1>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch18_03.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><B><FONT FACE="ARIEL,HELVETICA,HELV,SANSERIF" SIZE="-1">Chapter 18<br>The java.util.zip Package</FONT></B></TD>
<td width=172 align=right valign=top><A HREF="ch18_05.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
</table>

&nbsp;
<hr align=left width=515>
</DIV>
<DIV CLASS=refnamediv>
<H1>Checksum</H1>

<H2>Name</H2>

Checksum

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="ch18-REFSECT1-AUTOID.22">Synopsis</A></h2>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Interface Name:<br>
<DD>

<P CLASS=para>
<tt CLASS=literal>java.util.zip.Checksum</tt>

<p>
<DT CLASS=varlistentry>Super-interface:<br>
<DD>

<P CLASS=para>
None

<p>
<DT CLASS=varlistentry>Immediate Sub-interfaces:<br>
<DD>

<P CLASS=para>
None

<p>
<DT CLASS=varlistentry>Implemented By:<br>
<DD>

<P CLASS=para>
<tt CLASS=literal>java.util.zip.Adler32</tt>, 
<tt CLASS=literal>java.util.zip.CRC32</tt>

<p>
<DT CLASS=varlistentry>Availability:<br>
<DD>

<P CLASS=para>
New as of JDK 1.1 </DL>
</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="ch18-REFSECT1-AUTOID.23">Description</A></h2>

<P CLASS=para>
The <tt CLASS=literal>Checksum</tt> interface defines 
the methods that are needed to compute a checksum value for a stream of 
data. The checksum value can be used for error checking purposes. Note, 
however, that the checksum value must fit into a <tt CLASS=literal>long</tt> value, so this interface 
is not suitable for cryptographic checksum algorithms. 

<P CLASS=para>
The <tt CLASS=literal>Adler32</tt> and <tt CLASS=literal>CRC32</tt> 
classes implement the <tt CLASS=literal>Checksum</tt> 
interface, using the Adler-32 and CRC-32 algorithms, respectively. The 
<tt CLASS=literal>CheckedInputStream</tt> and <tt CLASS=literal>CheckedOutputStream</tt> 
classes provide a higher-level mechanism for computing checksums on data 
streams. 

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="ch18-REFSECT1-AUTOID.24">Class Summary</A></h2>

<DIV CLASS=screen>
<P>
<PRE>
public abstract interface java.util.zip.Checksum {
  // Methods
  public abstract long getValue();
  public abstract void reset();
  public abstract void update(int b);
  public abstract void update(byte[] b, int off, int len);
}
</PRE>
</DIV>

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="ch18-REFSECT1-AUTOID.25">Methods</A></h2>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch18-REFSECT2-AUTOID.12">getValue</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch18-REFSECT3-AUTOID.16">public abstract long getValue()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
The current checksum value. 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method returns the current value of this checksum. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch18-REFSECT2-AUTOID.13">reset</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch18-REFSECT3-AUTOID.17">public abstract void reset()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method resets the checksum to its initial value, making it appear as though 
it has not been updated by any data. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="ch18-REFSECT2-AUTOID.14">update</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch18-REFSECT3-AUTOID.18">public abstract void update(int b)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>b</tt><br>
<DD>

<P CLASS=para>
The value to be added 
to the data stream for the checksum calculation. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method adds the specified value to the data stream and updates the 
checksum value. The method uses only the lowest eight bits of the given 
<tt CLASS=literal>int</tt>. </DL>
</DIV>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="ch18-REFSECT3-AUTOID.19">public abstract void update(byte[] b, int off, int len)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><tt CLASS=literal>b</tt><br>
<DD>

<P CLASS=para>
An array of bytes to 
be added to the data stream for the checksum calculation.

<p>
<DT CLASS=varlistentry><tt CLASS=literal>off</tt><br>
<DD>

<P CLASS=para>
An offset into the byte array.

<p>
<DT CLASS=varlistentry><tt CLASS=literal>len</tt><br>
<DD>

<P CLASS=para>
The number of bytes to use. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
This method adds <tt CLASS=literal>len</tt> bytes 
from the specified array, starting at <tt CLASS=literal>off</tt>, 
to the data stream and updates the checksum value. </DL>
</DIV>

</DIV>

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="ch18-REFSECT1-AUTOID.26">See Also</A></h2>

<P CLASS=para>
<tt CLASS=literal>Adler32</tt>, 
<tt CLASS=literal>CheckedInputStream</tt>, 
<tt CLASS=literal>CheckedOutputStream</tt>, 
<tt CLASS=literal>CRC32</tt> 
</DIV>


<DIV CLASS=htmlnav>

<P>
<HR align=left width=515>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch18_03.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><a href="index.htm"><img src='gifs/txthome.gif' border=0 alt='Home'></a></td>
<td width=172 align=right valign=top><A HREF="ch18_05.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
<tr>
<td width=172 align=left valign=top>CheckedOutputStream</td>
<td width=171 align=center valign=top><a href="index/idx_0.htm"><img src='gifs/index.gif' alt='Book Index' border=0></a></td>
<td width=172 align=right valign=top>CRC32</td>
</tr>
</table>
<hr align=left width=515>

<IMG SRC="gifs/smnavbar.gif" USEMAP="#map" BORDER=0> 
<MAP NAME="map"> 
<AREA SHAPE=RECT COORDS="0,0,108,15" HREF="../javanut/index.htm"
alt="Java in a Nutshell"> 
<AREA SHAPE=RECT COORDS="109,0,200,15" HREF="../langref/index.htm" 
alt="Java Language Reference"> 
<AREA SHAPE=RECT COORDS="203,0,290,15" HREF="../awt/index.htm" 
alt="Java AWT"> 
<AREA SHAPE=RECT COORDS="291,0,419,15" HREF="../fclass/index.htm" 
alt="Java Fundamental Classes"> 
<AREA SHAPE=RECT COORDS="421,0,514,15" HREF="../exp/index.htm" 
alt="Exploring Java"> 
</MAP>
</DIV>

</BODY>
</HTML>
